import util from '../../utils/util.js'
import api from '../../api/api.js'
const { $Toast,$Message  } = require('../../dist/base/index');
 
Page({
  data:{
    Page:true,
    pg:true,
    interestList:[],
    toggle: false,
    NoMes:false,
    btnDel: false,
    actions2: [
      {
        name: '确定',
        
      }
    ]
  },
  onLoad:function(options){
 
    this.getSession();
    
  },
  getSession(){
    
    try{
      var value=wx.getStorageSync("items");
      if(value){
        this.setData({
          NoMes: false,
          interestList: value
        })
        
      }else{
      
        this.setData({
          NoMes:true,
          interestList:[],
        })
      }
    }catch(e){

    }
  },
  onReady:function(){
    setInterval(this.interVal, 1000);
    // 页面渲染完成
    this.getSession();
  },
  onShow:function(){
    // 页面显示
    this.getSession();
   
  },
  onHide:function(){
    // 页面隐藏
    this.getSession();
  },
  onUnload:function(){
    // 页面关闭
    this.getSession();
  },
  handleClickItem2(event) {
     var that=this;
    var id = event.currentTarget.dataset.detail.id;
    try{
      var value=wx.getStorageSync("items");
      if(value){
        that.setData({
          NoMes: false ,
         })
        for(let j in value){
         if(value[j].id==id){
            value.splice(j,1);
             wx.setStorageSync("items", value); 
           if (!value.length) {
             that.setData({
               NoMes: true,
               
             })
           }
            $Toast({
              content: '删除成功',
              type: 'success'
            });
            setTimeout(() => {
              that.setData({
                btnDel: false,
              });
              }, 100);
            

           
           that.getSession();
          }
        }
         

      }
    }catch(e){}

  },
  handleClickItem1(event,detail) {
     const index = detail.index + 1;
    console.log(index);
    console.log(event);
  },
  handleCancel2(){
    var that=this;
     setTimeout(() => {
       that.setData({
        btnDel: false,
       });
       }, 100);
  },
  actionsTap() {
    this.setData({
      btnDel:true
    })
   
       
   
  },
  interVal() {
    var got = Date.parse(new Date()) / 1000;

    if (got > util.heal) {
     this.setData({
        Page: false,
        pg: true
      })
    }else{
      this.setData({
        Page: true,
        pg: false
      })
    };
  }
 
})